import variable from "@/style/variables.module.scss";
export const useSettingStore = defineStore(
  "setting",
  () => {
    // variable
    // 将主题划分为当前正在使用的颜色， 和选择的颜色
    const settings = reactive({
      theme: variable.theme,
      originalTheme: "",
      tagViewFlag: false,
      sidebarLogo: false // 侧边栏上的logo显示状态
    });

    type ISetting = typeof settings;
    // 修改主题状态
    // 这里需要加入泛型，进行类型约束
    const changeSetting = <T extends keyof ISetting>({
      key,
      value
    }: {
      key: T;
      value: ISetting[T];
    }) => {
      settings[key] = value;
    };

    return {
      settings,
      changeSetting
    };
  },
  {
    persist: {
      storage: sessionStorage,
      pick: ["settings.theme", "settings.tagViewFlag", "settings.sidebarLogo"]
    }
  }
);
